package com.ruoyi.emergency.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.github.pagehelper.PageInfo;
import com.ruoyi.emergency.service.IEmergencyDeviceService;
import com.ruoyi.emergency.domain.EmergencyDeviceClass;
import com.ruoyi.emergency.dto.EmergencyDeviceDto;
import com.ruoyi.emergency.mapper.EmergencyDeviceClassMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.emergency.mapper.EmergencyDeviceMapper;
import com.ruoyi.emergency.domain.EmergencyDevice;

/**
 * 应急救援物资Service业务层处理
 * 
 * @author hcc
 * @date 2024-11-17
 */
@Service
public class EmergencyDeviceServiceImpl extends ServiceImpl<EmergencyDeviceMapper, EmergencyDevice> implements IEmergencyDeviceService //修改
{
    @Autowired
    private EmergencyDeviceMapper emergencyDeviceMapper;

    @Autowired
    private EmergencyDeviceClassMapper emergencyDeviceClassMapper;

    /**
     * 查询应急救援物资
     * 
     * @param id 应急救援物资主键
     * @return 应急救援物资
     */
    @Override
    public EmergencyDevice selectEmergencyDeviceById(Long id)
    {
        return emergencyDeviceMapper.selectEmergencyDeviceById(id);
    }

    /**
     * 查询应急救援物资列表
     * 
     * @param emergencyDevice 应急救援物资
     * @return 应急救援物资
     */
    @Override
    public List<EmergencyDevice> selectEmergencyDeviceList(EmergencyDevice emergencyDevice)
    {
        return emergencyDeviceMapper.selectEmergencyDeviceList(emergencyDevice);
    }

    /**
     * 新增应急救援物资
     * 
     * @param emergencyDevice 应急救援物资
     * @return 结果
     */
    @Override
    public int insertEmergencyDevice(EmergencyDevice emergencyDevice)
    {
        return emergencyDeviceMapper.insertEmergencyDevice(emergencyDevice);
    }

    /**
     * 修改应急救援物资
     * 
     * @param emergencyDevice 应急救援物资
     * @return 结果
     */
    @Override
    public int updateEmergencyDevice(EmergencyDevice emergencyDevice)
    {
        return emergencyDeviceMapper.updateEmergencyDevice(emergencyDevice);
    }

    /**
     * 批量删除应急救援物资
     * 
     * @param ids 需要删除的应急救援物资主键
     * @return 结果
     */
    @Override
    public int deleteEmergencyDeviceByIds(Long[] ids)
    {
        return emergencyDeviceMapper.deleteEmergencyDeviceByIds(ids);
    }

    /**
     * 删除应急救援物资信息
     * 
     * @param id 应急救援物资主键
     * @return 结果
     */
    @Override
    public int deleteEmergencyDeviceById(Long id)
    {
        return emergencyDeviceMapper.deleteEmergencyDeviceById(id);
    }

    @Override
    public PageInfo<EmergencyDeviceDto> getDeviceList(EmergencyDevice emergencyDevice) {
        List<EmergencyDevice> emergencyDevices = emergencyDeviceMapper.selectEmergencyDeviceList(emergencyDevice);
        PageInfo<EmergencyDeviceDto> pageInfo = new PageInfo<>();
        List<EmergencyDeviceDto> collect = emergencyDevices.stream().map(emergencyDevice1 -> {
            EmergencyDeviceDto emergencyDeviceDto = new EmergencyDeviceDto();
            BeanUtils.copyProperties(emergencyDevice1, emergencyDeviceDto);
            EmergencyDeviceClass emergencyDeviceClass = emergencyDeviceClassMapper.selectEmergencyDeviceClassById(emergencyDevice1.getClassId());
            emergencyDeviceDto.setClassName(emergencyDeviceClass.getName());
            return emergencyDeviceDto;
        }).collect(Collectors.toList());
        pageInfo.setList(collect);
        return pageInfo;
    }
}
